from flask import g, jsonify
from info.modules.release_house_check import check_house_blu
from info.response_code import RET
from info.utils.common import user_login
from info.models import House


@check_house_blu.route("/user/houses")
@user_login
def get_house_li():
    """
    1.判断用户是否登陆
    2.判断登陆的用户是否实名认证,如果未实名认证,就将其跳转到实名认证界面
    3.如果已经实名认证,就跳转到发布新房源的界面,并且显示已发布的房源列表
    """
    user = g.user
    if not user:
        return jsonify(errno=RET.SESSIONERR, errmsg="用户未登录")

    houses = House.query.filter(user.id == House.user_id).order_by(House.create_time.desc()).all()

    houses_li = [house.to_basic_dict() for house in houses]

    return jsonify(errno=RET.OK, errmsg="OK", data=houses_li)